<?php
/**
 * 维修相关接口请求参数验证器
 * Created by PhpStorm.
 * User: LRChang
 * Date: 2018/5/28
 * Time: 16:52
 * Mail: hjklrchang@qq.com
 */

namespace app\adminapi\validate;

use app\base\validate\BaseValidate;

class MaintenanceValidate extends BaseValidate
{
    protected $rule = [
        'page' => 'isPositiveInt',
        'pagenum' => 'isPositiveInt',
//        'fields' => '',
        'where_json' => 'isWhereJson',

        'maintenance_id' => 'require|isPositiveInt',
        'company_id' => 'require|isPositiveInt',
        'maintenance_name' => 'require|max:100',
        'charge_person' => 'require|max:50',
        'contact_number' => 'require|number|min:11|max:15',
        'scale' => 'require|in:1,2,3',
        'address' => 'require|max:255',
        'remark' => 'max:255',
        'start_date' => 'require|dateFormat:Y-m-d',
        'end_date' => 'require|dateFormat:Y-m-d',

        'maintenance_ids' => 'require|checkIDs',
    ];

    // 默认值
    protected $default = [
        'page' => 1,
        'pagenum' => 20,
        'where_json' => '',
        'fields' => '*',
    ];

    protected $message = [
        'page.isPositiveInt' => '页数只能为正整数',
        'pagenum.isPositiveInt' => '每页数量只能为正整数',
        'fields.isNotEmpty' => '字段不能为空',
        'where_json.isWhereJson' => '不是合法的json字符串',
        'maintenance_ids.checkIDs' => "maintenance_id 必须为正整数，多个请用','号连接"
    ];

    protected $scene = [
        'list' => ['page' ,'pagenum', 'fields', 'where_json'],
        'add' => [
            'company_id',
            'maintenance_name',
            'charge_person',
            'contact_number',
            'scale',
            'address',
            'remark',
            'start_date',
            'end_date',
        ],
        'edit' => [
            'maintenance_id',
            'company_id',
            'maintenance_name',
            'charge_person',
            'contact_number',
            'scale',
            'address',
            'remark',
            'start_date',
            'end_date',
        ],
        'delete' => [ 'maintenance_ids' ],
    ];
}